redis.log(redis.LOG_NOTICE,KEYS[1]) --game_prize_timestamp_gameID
redis.log(redis.LOG_NOTICE,KEYS[2]) --game_prize_gameID
redis.log(redis.LOG_NOTICE,KEYS[3]) --game_user_gameID
redis.log(redis.LOG_NOTICE,ARGV[1]) --userlimit
redis.log(redis.LOG_NOTICE,ARGV[2]) --userid

local user_limit = tonumber(ARGV[1])
local user_id = ARGV[2]
local user_count = redis.call('hget',KEYS[3],user_id)
user_count = tonumber(user_count~=nil and user_count or '0') --三目运算符 ?:
if user_count >= user_limit then
    return 0 --超限
else
    local now = redis.call('TIME')
    local curtime = now[1]*1000+now[2]/1000
    redis.log(redis.LOG_NOTICE,curtime)

    redis.replicate_commands()
    local rain_timestamp_ms = redis.call('lpop',KEYS[1])
    redis.log(redis.LOG_NOTICE,rain_timestamp_ms)
    if rain_timestamp_ms ~= false then
        if ( tonumber(rain_timestamp_ms) > curtime ) then
            redis.call('lpush',KEYS[1],rain_timestamp_ms)
            return 1 --没有抽到
        else
            redis.call('hset',KEYS[3],user_id,user_count+1)
            return redis.call('lpop',KEYS[2])
        end
    else
        return 2 --活动结束
    end
end